﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Drawing.Imaging;
using System.Threading;
using System.Resources;
using System.IO;

namespace InstitutionAssitant
{
    /// <summary>
    /// ClassName:frmAbout
    /// Version:1.0
    /// Date:2016-06-23
    /// Author:seanouyang
    /// </summary>
    /// <remarks>
    /// 本类是一WinForm 窗体,本窗体主要为实现系统版本信息显示
    /// 任意键或鼠标单击则关闭系统
    /// </remarks>
    public partial class frmProcessing : Form
    {
        #region 00.自定义属性
        public string m_strHint = "";   // 提示信息
        public Boolean m_bResult = false; // 事务处理结果
        public Boolean m_bIsTaskBegin = false; // 是否开始
        public Boolean m_bIsTaskFinish = false; // 是否结束
        int m_nTimes = 0;   // 计时
        #endregion
        public frmProcessing()
        {
            InitializeComponent();            
        }
        
        #region 01.自定义方法
        /// <summary>
        /// 初始化
        /// </summary>
        private void _init()
        {
            lblInfo.Text = m_strHint;
        }

        /// <summary>
        /// 数据处理
        /// </summary>
        private void _deal()
        {
            try
            {
                m_bResult = true;
                //m_bResult = DataDeal._getWebserviceInfo();
            }
            catch
            {
                MessageBox.Show("数据处理过程可能出现意外，请核实！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            m_bIsTaskFinish = true;
            this.Close();
        }
        #endregion

        #region 02.系统事件方法     
        private void frmAbout_Load(object sender, EventArgs e)
        {
            // 初始化
            _init();
            CheckForIllegalCrossThreadCalls = false;
            pbLoading.Image = InstitutionAssitant.Properties.Resources.Loading;
            // 设置时间任务
            System.Timers.Timer timer = new System.Timers.Timer(100);//实例化Timer类，设置间隔时间为100毫秒； 
            timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Tick);//到时间的时候执行事件； 
            timer.AutoReset = true;//设置是执行一次（false）还是一直执行(true)； 
            timer.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件； 
        }                 

        private void timer_Tick(object sender, EventArgs e)
        {
            // 00 起动任务
            if (!m_bIsTaskBegin)
            {
                m_bIsTaskBegin = true;
                Thread thread0 = new Thread(new ThreadStart(_deal));//创建线程
                thread0.IsBackground = true;
                thread0.Start();
            }
            // 01 计时
            m_nTimes++;
            lblInfo.Text = string.Format("{0}({1:0.0}秒)", m_strHint, m_nTimes * 0.1);
        }
        #endregion
    }
}